/*********************************************************************************
 Name: Kaide Laoshi
 Teacher#: 1
 Date: Feb 2, 2025
 Class#: 1, 2, & 3
 
 Description: This program is used for finding the GCF between two numbers that are given by the user.
 ********************************************************************************************************************************/

#include <iostream>
#include <string>

using namespace std;

void main()
{
	//two variable created to hold the 1st and 2nd number from the user. 
	int number1, number2;

	//Will hold the value of when we mod (%) our numbers. 
	int modAnswer = 0;

	//Tells the user what this program is used for. 
	cout << "This program is for finding the GCF between two numbers." << endl<<endl;

	//Asking the user for the first number and getting it from them. 
	cout << "Please enter the first number: ";
	cin >> number1;
	

	//Same as above, but for the second number. 
	cout << endl << "Please enter the second number: ";
	cin >> number2;


	/* 
	 We need to be able to make sure we "mod" by the smaller number. 
	 Big number % smaller number. How should we do this? Well, we can use an if, else.
	*/


	//If number1 is bigger we do num1%num2
	if (number1 > number2)
	{
		modAnswer = number1 % number2;
	}
	//If number2 is bigger we do num2%num1
	else if (number2 > number1)
	{
		modAnswer = number2 % number1;
	}
	/*
	* Why do we have this else statement? Because what if number1 == number? 
	* What should we mod (%) by if that happens?
	* In this scenario it actually is acceptable to write an IF,Else only. 
	* The else statement will actually handle this scenario, but that won't always be
	* case. 
	* Can you corrent this IF, else if, else to be an IF, Else?
	*/
	else
	{
		modAnswer = number1 % number2;
	}

	while (modAnswer != 0)
	{
		number1 = number2;
		number2 = modAnswer;

		modAnswer = number1 % number2;
	}

	/*This step is returning the correct answer, but look at the variable number2.
	Why is it incorrect when I try to give the 2 original numbers to the user?
	Can you figure out what you should do to output the original numbers and the answer? 
	"The GCF of 18 and 12 is: 6" --> This is what the user should get. 
	Right now the user gets this. --> "The GCF of 18 and 6 is: 6"
	*/
	cout << endl << "The GCF of " << number1 << " and " << number2 << " is: " << abs(number2) << endl << endl;

	//abs() is the absolute of a number. This guarentees that the number will be positive. A GCF should always be positive.
	//Negative numbers can have a GCF --> -18 and -12. Their GCF a positive 6. abs() helps us return that value. 

	//This command allows us to keep the console open until we want to close it. 
	//This is true, even if we run the .exe file outside of visual studios.
	system("pause");
}
